import math

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def simplify_fraction(numerator, denominator):
    if numerator == 0:
        return 0, 1
    common_divisor = gcd(numerator, denominator)
    simplified_numerator = numerator // common_divisor
    simplified_denominator = denominator // common_divisor
    if simplified_denominator < 0:
        simplified_numerator = -simplified_numerator
        simplified_denominator = -simplified_denominator
    return simplified_numerator, simplified_denominator
def add_fractions(n1, d1, n2, d2):
    numerator = n1 * d2 + n2 * d1
    denominator = d1 * d2
    return simplify_fraction(numerator, denominator)
def subtract_fractions(n1, d1, n2, d2):
    numerator = n1 * d2 - n2 * d1
    denominator = d1 * d2
    return simplify_fraction(numerator, denominator)
def multiply_fractions(n1, d1, n2, d2):
    numerator = n1 * n2
    denominator = d1 * d2
    return simplify_fraction(numerator, denominator)
def divide_fractions(n1, d1, n2, d2):
    if n2 == 0 or d2 == 0:
        raise ValueError("除数不能为零")
    numerator = n1 * d2
    denominator = d1 * n2
    return simplify_fraction(numerator, denominator)
def main():
    n1 = int(input())
    d1 = int(input())
    operator = int(input())
    n2 = int(input())
    d2 = int(input())
    if operator == 1:
        result = add_fractions(n1, d1, n2, d2)
    elif operator == 2:
        result = subtract_fractions(n1, d1, n2, d2)
    elif operator == 3:
        result = multiply_fractions(n1, d1, n2, d2)
    elif operator == 4:
        result = divide_fractions(n1, d1, n2, d2)
    else:
        raise ValueError("无效的运算符")
    print(result[0])
    print(result[1])
if __name__ == "__main__":
    main()